<template>
  <div class="student-score">
    <h3>学生成绩列表</h3>
    <div class="input_box">
      <span class="querySpans">查询条件：</span>
      <el-select
        filterable
        v-model="selectData.season"
        placeholder="考季"
        clearable
        size="small"
      >
        <el-option v-for="item in seasonList" :label="item.name" :key="item.id" :value="item.id"></el-option>
      </el-select>
      <el-select
        filterable
        v-model="selectData.subject"
        placeholder="科目"
        clearable
        size="small"
      >
        <el-option v-for="item in subjectList" :label="item.name" :key="item.id" :value="item.id"></el-option>
      </el-select>
      <el-button class="selectBtn" size="small" @click="getList(1,page_option.page_size)">查询</el-button>
      <el-button class="resetBtn" size="small" @click="reset()">重置</el-button>
    </div>
    <div class="table">
      <el-table :data="tableData" border style="width: 100%;text-align:center" size="small">
        <el-table-column prop="seasonName" label="考季"></el-table-column>
        <el-table-column prop="subjectName" label="科目"></el-table-column>
        <el-table-column prop="examinationName" label="考试课程"></el-table-column>
        <el-table-column prop="score" label="分数"></el-table-column>
      </el-table>
    </div>
    <div class="footer">
      <div class="pagination">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="page_option.current_page"
          :page-sizes="[15, 20, 30, 50]"
          :page-size="page_option.page_size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="page_option.total"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      seasonList: [],
      subjectList: [],
      selectData: {
        season: "",
        subject: ""
      },
      tableData: [
        // { id: 0, season: "2020期中考试", subject: "英语", course: "英语3", score: "90" },
        // { id: 1, season: "2020期中考试", subject: "英语", course: "英语4", score: "95" },
        // { id: 2, season: "2020期末考试", subject: "数学", course: "线性代数", score: "99" }
      ],
      page_option: {
        current_page: 1,
        page_size: 15,
        total: 0
      }
    };
  },
  computed: {
    tableSize() {
      return this.$store.getters.tableSize;
    }
  },
  mounted() {
    this.getSeasonList();
    this.getSubjectList()
    this.getList(1, this.page_option.page_size);
  },
  methods: {
    reset() {
      this.selectData = {
        season: "",
        subject: ""
      };
      this.page_option.current_page = 1;
      this.page_option.page_size = 15;
      this.getList(1, 15);
    },
    getSeasonList() {
      let data = {
        name: "",
        pageSize: 100,
        pageNum: 1,
      };
      console.log(data, "请求参数");
      this.$api.education.getSeasonList(data)
        .then((res) => {
          if (res.code === 200) {
            let data = res.data;
            this.seasonList = data.list;
          }
        });
    },
    getSubjectList() {
      this.$api.education.subjectList({
        pageNum: 1,
        pageSize: 100
      }).then((res) => {
        if (res.code === 200) {
          console.log(res);
          this.subjectList = res.data.list;
        }
      });
    },
    //获取表格数据,current（当前页）、size（一页显示几条数据）两个参数
    getList(pageNum, pageSize) {
      let params = {
        season: this.selectData.season,
        subject: this.selectData.subject,
        pageSize,
        pageNum
      };
      this.$api.studentScoreQuery.getMyExamList(params)
        .then((res) => {
          console.log(res);
          this.tableData = res.data.list;
          this.page_option.total = res.data.total
        });
    },
    handleSizeChange(size) {
      console.log(size);
      this.page_option.page_size = size;
      this.page_option.current_page = 1;
      this.getList(
        1,
        this.page_option.page_size
      );
    },
    handleCurrentChange(current) {
      this.page_option.current_page = current;
      this.getList(
        this.page_option.current_page,
        this.page_option.page_size
      );
    },
    //编辑
    // 更改开启状态
    //删除
    // handleDelete(row) {
    //   this.$confirm("是否确认删除此会员?", "提示", {
    //     confirmButtonText: "确定",
    //     cancelButtonText: "取消",
    //     type: "warning"
    //   }).then(() => {
    //     this.$store.dispatch("DelUserMember", { userId: row.id }).then(res => {
    //       this.$message.success("删除成功！");
    //       this.getList(
    //         this.page_option.current_page,
    //         this.page_option.page_size
    //       );
    //     }).catch((err) => {console.log(err);});
    //   }).catch(() => {
    //     this.$message({
    //       type: "info",
    //       message: "已取消删除"
    //     });
    //   });
    // },
    //添加用户
    addAdministrator() {
      this.$router.push({ path: "/studentInfo/subjectScore/add" });
    },
    option() {
      return {
        userId: "", lockState: "", phone: ""
      };
    }
  }
};
</script>
<style scoped>
@import url('./list.css');
</style>

